#!/bin/bash


[ $(ps -ef|grep utelnetd|wc -l) -eq 1 ] && utelnetd -l /bin/sh &
#============samba局域网共享===========================
if [ $(ps -ef|grep smbd|wc -l) -eq 1 ] ;then
   [ -e /plugin/conf/smb.conf ] && smbd -s /plugin/conf/smb.conf -D  &     #局域网开启指令
fi 



if [ $(/opt/bin/opkg |wc -l) -eq 0 ] ;then
   if [ ! -e /plugin/123.img ] ;then
      if [ -e /mnt/disk1_1/luyou/123.img ] ;then
            echo "复制配置文件到 /plugin/"
            cp -a /mnt/disk1_1/luyou/* /plugin/
      else
         echo "没有安装entware ,且不存在 /plugin/123.img, 退出！！！！！！！！"
         exit 1
      fi
   fi
   #=========挂载镜像到 /opt  安装。。。。
   /plugin/busybox-armv7l mount -o loop -t ext4 /plugin/123.img /opt 

   
   echo '安装过程：调整配置用户'
   chmod 777 /opt/tmp
   [ -f /etc/localtime ] && ln -sf /etc/localtime /opt/etc/localtime
   for file in passwd group shells shadow gshadow; do
      if [ -f /etc/$file ]; then
         ln -sf /etc/$file /opt/etc/$file
      else
         [ -f /opt/etc/$file.1 ] && cp /opt/etc/$file.1 /opt/etc/$file
      fi
   done
   echo "Entware 安装完成"
fi


echo "准备：关闭之前开启的应用"
# umount -l /opt 
/opt/sbin/nginx -s quit
killall aria2c
sleep 1


echo "启动nginx"
ln -sf /plugin/conf/nginx.conf /opt/etc/nginx/nginx.conf
/opt/sbin/nginx &   
    

echo "启动aria2"
[ -e /opt/var/aria2/session.dat ] || /opt/bin/touch /opt/var/aria2/session.dat
ln -sf /plugin/conf/aria2.conf /opt/etc/aria2.conf
/opt/bin/aria2c --conf-path="/opt/etc/aria2.conf"  -D &
 



  
echo "命令执行完成"
exit 0

